﻿using UnityEngine;
using System.Collections;

public class MainMenu : MonoBehaviour {

    public SpriteRenderer[] elements;
    public Sprite[] elementsOn;
    public Sprite[] elementsOff;
    public Transform[] changePosition;

    private int i = 1;

    private bool reloadInput = true;

	void Update () 
    {
        if (Input.GetAxisRaw("Vertical") < 0 && reloadInput && i > 0)
        {
            changePosition[i].position = new Vector3(-1.87f, changePosition[i].position.y, changePosition[i].position.z);
            elements[i].sprite = elementsOff[i];
            i--;
            changePosition[i].position = new Vector3(-2.4f, changePosition[i].position.y, changePosition[i].position.z);
            elements[i].sprite = elementsOn[i];
            reloadInput = false;
            audio.Play();
        }

        if (Input.GetAxisRaw("Vertical") > 0 && reloadInput && i < elements.Length - 1)
        {
            changePosition[i].position = new Vector3(-1.87f, changePosition[i].position.y, changePosition[i].position.z);
            elements[i].sprite = elementsOff[i];
            i++;
            changePosition[i].position = new Vector3(-2.4f, changePosition[i].position.y, changePosition[i].position.z);
            elements[i].sprite = elementsOn[i];
            reloadInput = false;
            audio.Play();
        }


        if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
        {
            if (i == 0)
            {
                Debug.Log("Saindo");
            }

            if (i == 1)
            {
                Application.LoadLevel("GameExample");
            }
        }

        if (Input.GetAxisRaw("Vertical") == 0)
        {
            reloadInput = true;
        }
	}
}
